{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=49
  Verdict: Accepted
}
uses 
	SysUtils, Math;
 
var  	
	ca,cb,cc,t,i,kk:longint;
	a,b,c:array[0..1000010] of string;
	s:string;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
ca:=0;
cb:=0;
cc:=0;
while not eof do begin
	readln(S);
	kk:=pos(' ',s);
	if kk=0 then break;
	t:=strtoint(copy(s,1,kk-1));
	if t=9 then begin
		inc(ca);
		a[ca]:=s;
	end else
	if t=10 then begin
		inc(cb);
		b[cb]:=s;
	end else 
	if t=11 then begin
		inc(cc);
		c[cc]:=s;
	end;
end;
for i:=1 to ca do
	writeln(a[i]);
for i:=1 to cb do
	writeln(b[i]);
for i:=1 to cc do
	writeln(c[i]);
end.